import math

class Vec2:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    
    def __add__(self, rhs):
        x = self.x + rhs.x
        y = self.y + rhs.y
        return Vec2(x, y)

    def __sub__(self, rhs):
        x = self.x - rhs.x
        y = self.y - rhs.y
        return Vec2(x, y)

    def __mul__(self, n):
        x = self.x * n
        y = self.y * n
        return Vec2(x, y)

    def __truediv__(self, n):
        x = self.x / n
        y = self.y / n
        return Vec2(x, y)

    def set_val(self, v):
        self.x = v.x
        self.y = v.y

    def __eq__(self, v):
        return self.x == v.x and self.y == v.y

    def length(self):
        return math.sqrt(self.x ** 2 + self.y ** 2)

    def dot(self, v):
        return self.x * v.x + self.y * v.y

    def proj(self, v):
        v.normalize()
        return self.dot(v)

    def normalize(self):
        s = self.length()
        if s != 0:
            self.x = self.x / s
            self.y = self.y / s

    def output(self):
        print(self.x, self.y)

class Vec3:
    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z
    
    def __add__(self, rhs):
        x = self.x + rhs.x
        y = self.y + rhs.y
        z = self.z + rhs.z
        return Vec3(x, y, z)

    def __sub__(self, rhs):
        x = self.x - rhs.x
        y = self.y - rhs.y
        z = self.z - rhs.z
        return Vec3(x, y, z)

    def __mul__(self, n):
        x = self.x * n
        y = self.y * n
        z = self.z * n
        return Vec3(x, y, z)

    def __truediv__(self, n):
        if n == 0:
            print("divide by zero!")
            return None
        x = self.x / n
        y = self.y / n
        z = self.z / n
        return Vec3(x, y, z)

    def set_val(self, v):
        self.x = v.x
        self.y = v.y
        self.z = v.z

    def to_vec4(self, w):
        return Vec4(self.x, self.y, self.z, w)

    def __eq__(self, v):
        return self.x == v.x and self.y == v.y and self.z == v.z

    def length(self):
        return math.sqrt(self.x ** 2 + self.y ** 2 + self.z ** 2)

    def dot(self, v):
        return self.x * v.x + self.y * v.y + self.z * v.z

    def cross(self, v):
        x = self.y * v.z - self.z * v.y
        y = self.z * v.x - self.x * v.z
        z = self.x * v.y - self.y * v.x
        return Vec3(x, y, z)

    def proj(self, v):
        v.normalize()
        return self.dot(v)

    def normalize(self):
        s = self.length()
        if s != 0:
            self.x = self.x / s
            self.y = self.y / s
            self.z = self.z / s

    def output(self):
        print(self.x, self.y, self.z)

class Vec4:
    def __init__(self, x, y, z, w):
        self.x = x
        self.y = y
        self.z = z
        self.w = w

    def __add__(self, rhs):
        x = self.x + rhs.x
        y = self.y + rhs.y
        z = self.z + rhs.z
        w = self.w + rhs.w
        return Vec4(x, y, z, w)

    def __sub__(self, rhs):
        x = self.x - rhs.x
        y = self.y - rhs.y
        z = self.z - rhs.z
        w = self.w - rhs.w
        return Vec4(x, y, z, w)

    def __mul__(self, n):
        x = self.x * n
        y = self.y * n
        z = self.z * n
        w = self.w * n
        return Vec4(x, y, z, w)

    def __truediv__(self, n):
        if n == 0:
            print("divide by zero!")
            return None
        x = self.x / n
        y = self.y / n
        z = self.z / n
        w = self.w / n
        return Vec4(x, y, z, w)

    def dot(self, v):
        return self.x * v.x + self.y * v.y + self.z * v.z + self.w * v.w

    def set_val(self, v):
        self.x = v.x
        self.y = v.y
        self.z = v.z
        self.w = v.w

    def to_vec3(self):
        return Vec3(self.x, self.y, self.z)

    def output(self):
        print(self.x, self.y, self.z, self.w)
